package com.nondo.rdp.finance.endpoint.api.app.user;

import com.nondo.rdp.auth.common.UserUtils;
import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.common.CommUtil;
import com.nondo.rdp.core.model.View;
import com.nondo.rdp.finance.domain.log.SignLog;
import com.nondo.rdp.finance.service.log.SignLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


@RestController("apiAppUserPoint")
@RequestMapping("/api/app/user/point")
public class PointEndpoint {
    @Autowired
    SignLogService signLogService;

    /**
     * 积分中心
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "")
    public View findOne(HttpServletRequest request, HttpServletResponse response) {
        View view = new View(20000, "获取成功");
        User user = UserUtils.getUser(request, response);

        Map map = new HashMap();
        map.put("points", user.getPoints());

        //判断今天是否已经签到了
        Date todayStartTime = CommUtil.getTodayZeroTime();
        SignLog todaySing = this.signLogService.findByUserAndCreateDateAfter(user, todayStartTime);
        if (todaySing == null) {
            map.put("isSignTody", 0);
        } else {
            map.put("isSignTody", 1);
        }

        view.setData(map);

        return view;
    }
}